package net.kong.sns.rest.client.pay;

import net.kong.sns.rest.client.method.JsonMethodInvokeBase;
import net.kong.sns.rest.client.rest.HttpResponseContent;
import net.kong.sns.rest.client.InvalidResponseException;
import net.kong.sns.rest.client.KongApiMethod;

import java.util.Map;

/**
 * @author <a href="mailto:lanhuai@gmail.com">Ning Yubin</a>
 * @version $Id: PayIsCompletedMethodInvoke.java,v 1.3 2009/11/04 17:17:38 ningyubin Exp $
 */
public class PayIsCompletedMethodInvoke extends JsonMethodInvokeBase<Boolean> {
    public enum Result {
        SUCCESS("1");

        Result(String result) {
            this.result = result;
        }

        private String result;

        public String getResult() {
            return result;
        }
    }
    public PayIsCompletedMethodInvoke(long orderId) {
        super(KongApiMethod.PAY_IS_COMPLETED);
        setParameter("order_id", String.valueOf(orderId));
    }

    @Override
    protected Boolean processJsonResponse(HttpResponseContent responseData) throws InvalidResponseException {
        String response = responseData.getBody();
        Object o = reader.read(response);
        Map<String, Object> stringObjectMap = (Map<String, Object>) o;
        String result = (String) stringObjectMap.get("result");
        return result.equals(Result.SUCCESS.getResult());
    }
}
